<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加电影</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form action="#" id="f1">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">选择影厅</label>
            <div class="layui-input-block">
                <select name="hallId" >
                    <option value="1">CGV影城一号厅</option>
                    <option value="2">CGV影城二号厅</option>
                    <option value="3">万达影城一号厅</option>
                    <option value="4">万达影城二号厅</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">选择日期</label>
            <div class="layui-input-block">
                <select name="dateId" >
                    <option value="1">12月1日</option>
                    <option value="2">12月2日</option>
                    <option value="3">12月3日</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">选择场次</label>
            <div class="layui-input-block">
                <select name="sessId" >
                    <option value="1">第一场</option>
                    <option value="2">第二场</option>
                    <option value="3">第三场</option>
                    <option value="4">第四场</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">输入电影名</label>
            <div class="layui-input-block">
                <input v-model="name" @change="blur" id="name" type="text" name="name"  lay-reqtext="电影名不能为空"
                       placeholder="请输入电影名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">输入价格</label>
            <div class="layui-input-block">
                <input  type="number"  name="price" lay-verify="required" lay-reqtext="价格不能为空"
                       placeholder="请输入电影名" value="" class="layui-input">
                <input type="text" v-model="movieId" name="movieId" style="display: none">

            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" @click="add" class="layui-btn layui-btn-normal" lay-filter="saveBtn">
                    确认保存
                </button>
            </div>
        </div>
    </div>
    </div>
</form>
<!--引入axios-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            alert(data)
            var index = layer.alert("添加成功", {
                title: '最终的提交信息'
            }, function () {
                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            });
            // location.href = "/bs/session_list.html"
            return false;
        });

    });
</script>
<script>
    let vm = new Vue({
        el: "#f1",
        data: {
            hotMovie:[],
            name:"",
            movieId:""
        },
        methods: {
            add: function () {
                let data = new FormData(document.querySelector("#f1"));
                axios.post("/session/insertSession ", data).then(function (response) {
                   if (response.data==2){
                        alert("场次已被占用")
                        return;
                    }else {
                        alert("添加成功")
                    }
                })
            },
            blur:function () {
                axios.get("/movie/checkMovie?name="+vm.name).then(function (response) {
                    if (response.data==''){
                        alert("没有找到该影片")
                    }else {
                        vm.movieId=response.data;
                    }

                })
            }
        }
    })
</script>
</body>
</html>